import Vue from 'vue'
import Router from 'vue-router'
import index from '@/pages/index/index.vue'
import register from '@/pages/register/register.vue'
import store from '../store'
Vue.use(Router)


const routes = [
		{
			path: '/',
			name: "nav",
			redirect: '/index', // 路由重定向
			component: () => import('@/components/menu/nav'),
			children: [
				{
					path: '/index',
					name: 'index',
					component: index,
					meta:{
						title:'首页',
					}
				},
			]
		
	},
	{
		path: '/register',
		name: 'register',
		component: register,
		meta:{
			noAuth:true
		}
	},

]



const router = new Router({
	mode: 'history',
	routes
})


router.beforeEach((to, from, next) => {
	if (to.meta.noAuth) return next()
	if (!store.state.userInfo) return next('/register')
next()

})

export default router